//
// Created by liushuai on 2021/1/17.
//

#include "hasPathSum.h"
bool hasPathSum(TreeNode* root, int sum,int cache)  {
    if(!root)
        return false;
    else{
        cache += root->val;
        if(!root->left && !root->right && sum == cache)
            return true;
        else
            return hasPathSum(root->left,sum,cache)||hasPathSum(root->right,sum,cache);
    }
};
bool hasPathSum(TreeNode* root, int sum){
    return hasPathSum(root,sum,0);
}